package cn.kinggm520;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 作者: kinggm Email:731586355@qq.com
 * 时间:  2020-05-13 20:33
 */
@Configuration
public class RabbitMQConfig {

    //    定义交换机
    private static final String DIRECT_EXCHANGE = "direct_exchange";

    //    定义队列
    private static final String TEST_QUEUE = "test_queue";


    @Bean("direct_exchange")
    public Exchange directExchenge() {
        return ExchangeBuilder.directExchange(DIRECT_EXCHANGE).durable(true).build();
    }


    @Bean("test_queue")
    public Queue testQueue(){
        return QueueBuilder.durable(TEST_QUEUE).build();
    }


//    绑定
    @Bean("test_queue_exchange")
    public Binding bindingEX(@Qualifier("test_queue") Queue queue,
                             @Qualifier("direct_exchange") Exchange exchange){
        return BindingBuilder.bind(queue).to(exchange).with("test.ack").noargs();
    }


}
